package com.sccba.web.controller.yjcz;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.sccba.common.annotation.Log;
import com.sccba.common.core.controller.BaseController;
import com.sccba.common.core.domain.AjaxResult;
import com.sccba.common.core.page.TableDataInfo;
import com.sccba.common.enums.BusinessType;
import com.sccba.common.utils.poi.ExcelUtil;
import com.sccba.emtbusiness.domain.YjczFbChannel;
import com.sccba.emtbusiness.domain.YjczFbInfo;
import com.sccba.emtbusiness.domain.YjczHandleTimeLine;
import com.sccba.emtbusiness.service.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sccba.emtbusiness.domain.YjczProductEventInfo;

/**
 * 生产事件Controller
 * 
 * @author lichh
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/yjcz/productEvent")
public class YjczProductEventInfoController extends BaseController
{
    @Autowired
    private IYjczProductEventInfoService yjczProductEventInfoService;

    @Autowired
    private IYjczFbInfoService yjczFbInfoService;

    @Autowired
    private IYjczChannelInfoService yjczChannelInfoService;

    @Autowired
    private IYjczEmergencySceneService yjczEmergencySceneService;

    @Autowired
    private IYjczHandleTimeLineService yjczHandleTimeLineService;

    /**
     * 查询生产事件列表
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEvent:list')")
    @GetMapping("/list")
    public TableDataInfo list(YjczProductEventInfo yjczProductEventInfo)
    {
        startPage();
        List<YjczProductEventInfo> list = yjczProductEventInfoService.selectYjczProductEventInfoList(yjczProductEventInfo);
        return getDataTable(list);
    }

    /**
     * 导出生产事件列表
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEvent:export')")
    @Log(title = "生产事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YjczProductEventInfo yjczProductEventInfo)
    {
        List<YjczProductEventInfo> list = yjczProductEventInfoService.selectYjczProductEventInfoList(yjczProductEventInfo);
        ExcelUtil<YjczProductEventInfo> util = new ExcelUtil<YjczProductEventInfo>(YjczProductEventInfo.class);
        util.exportExcel(response, list, "生产事件数据");
    }

    /**
     * 获取生产事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEvent:query')")
    @GetMapping(value = "/{pkId}")
    public AjaxResult getInfo(@PathVariable("pkId") Long pkId)
    {
        return success(yjczProductEventInfoService.selectYjczProductEventInfoByPkId(pkId));
    }

    /**
     * 新增生产事件
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEvent:add')")
    @Log(title = "生产事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YjczProductEventInfo yjczProductEventInfo)
    {
        return toAjax(yjczProductEventInfoService.insertYjczProductEventInfo(yjczProductEventInfo));
    }

    /**
     * 修改生产事件
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEvent:edit')")
    @Log(title = "生产事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YjczProductEventInfo yjczProductEventInfo)
    {
        return toAjax(yjczProductEventInfoService.updateYjczProductEventInfo(yjczProductEventInfo));
    }

    /**
     * 删除生产事件
     */
    @PreAuthorize("@ss.hasPermi('yjcz:productEvent:remove')")
    @Log(title = "生产事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pkIds}")
    public AjaxResult remove(@PathVariable Long[] pkIds)
    {
        return toAjax(yjczProductEventInfoService.deleteYjczProductEventInfoByPkIds(pkIds));
    }


    @GetMapping("/listFbInfo")
    public AjaxResult listFbInfo(YjczFbInfo yjczFbInfo)
    {
        return success(yjczFbInfoService.selectFbInfoList(yjczFbInfo));
    }

    @GetMapping("/listChannelInfo/{fbId}")
    public AjaxResult listChannelInfo(@PathVariable("fbId") String fbId)
    {
        YjczFbChannel yjczFbChannel = new YjczFbChannel();
        yjczFbChannel.setFbId(Long.parseLong(fbId));
        return success(yjczChannelInfoService.selectChannelListByFbId(yjczFbChannel));
    }

    @PostMapping("/querySceneList")
    public AjaxResult querySceneList(@RequestBody Map<String, String> params)
    {
        return success(yjczEmergencySceneService.selectSceneByFbAndChannel(params.get("fbId"), params.get("channelId")));
    }

    @PostMapping("/queryAllScene")
    public AjaxResult queryAllScene()
    {
        return success(yjczEmergencySceneService.selectAllScene());
    }

    @PostMapping("/handleProductEvent")
    public AjaxResult handleProductEvent (@RequestBody YjczProductEventInfo yjczProductEventInfo) {
        return success(yjczProductEventInfoService.handleProductEvent(yjczProductEventInfo));
    }

    @PostMapping("/markDownNode")
    public AjaxResult markDownNode (@RequestBody YjczHandleTimeLine handleTimeLine) {
        yjczHandleTimeLineService.markDownLineNode(handleTimeLine);
        return success();
    }

    @GetMapping("/searchEvent/{pkId}")
    public AjaxResult searchEvent (@PathVariable("pkId") Long pkId) {
        return success(yjczProductEventInfoService.selectOneForSearch(pkId));
    }

    @PostMapping("/exportTimeLine")
    public void exportTimeLine(HttpServletResponse response, YjczProductEventInfo eventInfo)
    {
        yjczHandleTimeLineService.exportHandleTimeLine(response, eventInfo);
    }
}
